import ohoUserData from '../viewModel/ohoUserData'
import http from '@ohos.net.http'
import { JSON } from '@kit.ArkTS';

class UserModel {
  baseURL: string = 'http://127.0.0.1:8080'

  //1.创建http请求对象
    getUserList(): Promise<ohoUserData[]> {
    return new Promise((resolve, reject) => {
      //发http请求
      let httpRequest = http.createHttp()
      let promise = httpRequest.request(
        `${this.baseURL}/oho/user/list`,
        { method: http.RequestMethod.GET }
      )
        .then(resp => {
        if (resp.responseCode === 200) {
          resolve(resp.result as ohoUserData[])
        } else {
          console.log('查询出问题了');
        }
      }).catch(err => {
        console.log('查询出异常' + err);
      })
    })

  }
}

const userModel = new UserModel()

export default userModel as UserModel